package main.java.chessfootball.rules.checker;

import main.java.chessfootball.model.game.Field;
import main.java.chessfootball.model.game.Player;

/**
 * User: Igor
 * Date: 28.07.2011
 * Time: 21:42:20
 */
public class GoalkeeperChecker extends AbstractMoveChecker
{
	@Override
	public boolean valid()
	{
		if (game.getRule().getGame().isGoalkeeper())
		{
			if (move.getLength() > 1)
			{
				Player player = game.getField().getTeam(move.getSide().getInvert()).getPlayer(1);
				if (Field.PENALTY_AREA[game.getField().getTeam(player.getTeam().getSide()).getHalf().getId()].contains(player.getCell()))
				{
					for (int l = 1; l < move.getLength(); l++)
					{
						if (move.getVector().getCell(game.getField().getBall().getCell(), l).equals(player.getCell()))
						{
	                    	return false;
						}
					}
				}
			}
		}
		return true;
	}
}
